using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Mapping.Attributes;
using Lib;

namespace Persistance.Model
{

    [Serializable]
    [Class(Lazy = true)]
    public class Categories
    {
        #region " Mapping "

        /// <summary>
        /// This is needed for NH. NH only accepts numeric primary keys
        /// </summary>
        private int _categoryID;
        //NHIBER: Setts the primary key to ID
        [Id(Name = "CategoryID")]
        [Generator(1, Class = "native")]
        public virtual int CategoryID
        {
            get { return _categoryID; }
            set { _categoryID = value; }
        }

        //Parent Category
        private Categories _parentCategory;
        [ManyToOne(Column = "CategoryID", Cascade = CascadeStyle.All, ForeignKey = "FK_Situation")]
        public virtual Categories ParentCategory
        {
            get { return _parentCategory; }
            set { _parentCategory = value; }
        }

        //List of Child Categories. This implies that we can have many children to a parent
        private IList<Categories> _childCategories = new List<Categories>();
        [Key(2, Column = "CategoryID", ForeignKey = "CategoryToChildCategories")]
        [Bag(1, Inverse = true)]
        [OneToMany(3, ClassType = typeof(Categories))]
        public virtual IList<Categories> ChildCategories
        {
            get { return _childCategories; }
            set { _childCategories = value; }
        }

        private IList<Items> _items;
        [Bag(1, Inverse = true)]
        [Key(2, Column = "ItemID", ForeignKey = "CategoriesToItems")]
        [OneToMany(3, ClassType = typeof(Items))]
        public virtual IList<Items> Items
        {
            get { return _items; }
            set { _items = value; }
        }

        private string _name;
        [Property(Length = 100)]
        public virtual string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private int _numActiveItems;
        [Property(Type = "int")]
        public virtual int NumActiveItems
        {
            get { return _numActiveItems; }
            set { _numActiveItems = value; }
        }

        #endregion
    }

}
